package flc.ast;

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.stark.fcm.base.FcmModule;

import java.util.ArrayList;
import java.util.List;

import flc.ast.databinding.ActivityHomeBinding;
import flc.ast.fragment.HomeFragment;
import flc.ast.fragment.MyFragment;
import flc.ast.fragment.TacticsFragment;
import flc.ast.fragment.TeachFragment;
import stark.common.basic.base.BaseNoModelActivity;
import stark.common.basic.base.BaseTabFragmentHomeActivity;
import stark.common.basic.base.DefExitAppDialog;
import stark.common.basic.event.EventStatConstant;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.event.IEventStat;

public class HomeActivity extends BaseTabFragmentHomeActivity<ActivityHomeBinding> implements View.OnClickListener {

    @Override
    protected int getPageType() {
        return EventStatConstant.PAGE_TAB_HOME;
    }

    @Override
    public void onBackPressed() {
        FcmModule.getInstance().exitApp(this);
    }

    @Override
    protected void initView() {
        super.initView();
        EventStatProxy.getInstance().statLaunch(this);
    }

    @Override
    protected void initData() {
        FcmModule.getInstance().init(this);
    }

    @NonNull
    @Override
    protected List<BaseTabFragmentHomeActivity<ActivityHomeBinding>.FragmentViewBinder> getFragmentViewBinders() {
        List<FragmentViewBinder> listFragment = new ArrayList<>();
        listFragment.add(new FragmentViewBinder(HomeFragment.class, R.id.llHome));
        listFragment.add(new FragmentViewBinder(TeachFragment.class, R.id.llTeach));
        listFragment.add(new FragmentViewBinder(TacticsFragment.class, R.id.llTactics));
        listFragment.add(new FragmentViewBinder(MyFragment.class, R.id.llMy));
        return listFragment;
    }

    @Override
    protected void onFragmentViewClick(View view) {
        clearSelection();
        switch (view.getId()) {
            case R.id.llHome:
                mDataBinding.tvHome.setVisibility(View.VISIBLE);
                mDataBinding.rlHome.setVisibility(View.GONE);
                break;
            case R.id.llTeach:
                mDataBinding.tvTeach.setVisibility(View.VISIBLE);
                mDataBinding.rlTeach.setVisibility(View.GONE);
                break;
            case R.id.llTactics:
                mDataBinding.tvTactics.setVisibility(View.VISIBLE);
                mDataBinding.rlTactics.setVisibility(View.GONE);
                break;
            case R.id.llMy:
                mDataBinding.tvMy.setVisibility(View.VISIBLE);
                mDataBinding.rlMy.setVisibility(View.GONE);
                break;
        }
    }

    @Override
    protected int getFragmentContainerId() {
        return R.id.flHome;
    }

    @Override
    protected int onCreate() {
        return R.layout.activity_home;
    }

    private void clearSelection() {
        mDataBinding.tvHome.setVisibility(View.GONE);
        mDataBinding.rlHome.setVisibility(View.VISIBLE);
        mDataBinding.tvTeach.setVisibility(View.GONE);
        mDataBinding.rlTeach.setVisibility(View.VISIBLE);
        mDataBinding.tvTactics.setVisibility(View.GONE);
        mDataBinding.rlTactics.setVisibility(View.VISIBLE);
        mDataBinding.tvMy.setVisibility(View.GONE);
        mDataBinding.rlMy.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        FcmModule.getInstance().onActivityResult(requestCode, resultCode, data);
    }
}